package 网络编程;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Server {
    public static void main(String[] args) throws Exception {

        DatagramSocket socket = new DatagramSocket(6789);
        
        byte[] bytes = new byte[1024 * 64];
        while (true) {
            DatagramPacket packet = new DatagramPacket(bytes,bytes.length);

            socket.receive(packet);

            System.out.println(packet.getAddress().getHostAddress());
//            System.out.println(packet.getAddress());
            System.out.println(packet.getPort());

            String s = new String(bytes,0, packet.getLength());
            System.out.println(s);
            System.out.println("-------------------------");
        }
    }
    
    
}
